package cn.ch.train.business.controller.admin;

import cn.ch.train.business.request.StationQueryParam;
import cn.ch.train.business.request.StationSaveParam;
import cn.ch.train.business.response.StationQueryResult;
import cn.ch.train.business.service.StationService;
import cn.ch.train.common.response.CommonResponse;
import cn.ch.train.common.response.PageResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/station")
public class StationAdminController {
    @Autowired
    private StationService stationService;

    @PostMapping("/save")
    public CommonResponse save(@Valid @RequestBody StationSaveParam param) {
        stationService.save(param);
        return new CommonResponse<>();
    }

    @GetMapping("/query-list")
    public CommonResponse<PageResult<StationQueryResult>> queryList(@Valid StationQueryParam param) {
        PageResult<StationQueryResult> stationList = stationService.queryList(param);
        return new CommonResponse<>(stationList);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResponse delete(@PathVariable Long id) {
        stationService.delete(id);
        return new CommonResponse<>();
    }

    @GetMapping("/query-all")
    public CommonResponse<List<StationQueryResult>> queryAll() {
        List<StationQueryResult> stationList = stationService.queryAll();
        return new CommonResponse<>(stationList);
    }

}
